package com.dai.zhenfujin.adapter;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.dai.zhenfujin.BaseAdapter.BaseRecycleAdapter;
import com.dai.zhenfujin.BaseAdapter.BaseViewHolder;
import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.bean.BlackBean;
import com.dai.zhenfujin.bean.ProListBean;
import com.dai.zhenfujin.http.CallBack;
import com.dai.zhenfujin.http.HttpClient;
import com.dai.zhenfujin.utils.SPUtils;
import com.dai.zhenfujin.utils.UIUtils;
import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

public class AttentionDetailAdapter2 extends BaseRecycleAdapter<BlackBean.FollowListBean> {
    private List<BlackBean.FollowListBean> dataList;
    private Context mContext;
    private BaseViewHolder.onItemCommonClickListener commonClickListener;



    public AttentionDetailAdapter2(Context context, List<BlackBean.FollowListBean> dataList) {
        super(context, dataList, R.layout.itme_attention_list2);
        this.dataList = dataList;
        this.commonClickListener = commonClickListener;
        mContext = context;
    }

    @Override
    public void bindData(BaseViewHolder holder, BlackBean.FollowListBean data) {
        holder.setText(R.id.pp_adapter_name, data.user_name);
        Glide.with(mContext).load(data.user_logo).into((CircleImageView)holder.getView(R.id.cv_img));
        holder.getView(R.id.tv_remove).setOnClickListener(v -> {
            Map<String, Object> params = new HashMap<>();
            Map<String, String> params2 = new HashMap<>();
            params2.put("friend_id", data.friend_id);
            params2.put("type", 2 + "");
            params.put("req_bd", params2);
            HttpClient.post(mContext, Constants.BLACK, params, new CallBack<ProListBean>() {
                @Override
                public void onSuccess(ProListBean resultBean) throws HyphenateException {
                    EMClient.getInstance().contactManager().removeUserFromBlackList(data.friend_id);
                    SPUtils.saveBlackId(mContext,data.friend_id,false);
                    UIUtils.showToastSafe("移除成功");
                    dataList.remove(data);
                    notifyDataSetChanged();
                }
            });
        });
    }
}
